import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type { OperationRecord, OperationRecordSearchParams } from './model';

/**
 * 分页查询操作日志
 */
export async function pageOperationRecords(
  params: OperationRecordSearchParams
) {
  const res = await request.get<ApiResult<PageResult<OperationRecord>>>(
    '/log',
    { params }
  );
  if (res.data.code === 0) {
    return res.data.data?.records;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询操作日志列表
 */
export async function listOperationRecords(
  params?: OperationRecordSearchParams
) {
  const res = await request.get<ApiResult<OperationRecord[]>>('/log', {
    params
  });
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}
